class Simulator::SimulationBodiesController < ApplicationController
	layout 'simulator/simulator'

	
	def add_planets_to_simulation
		@simulation = Simulation.find_by_id(params[:id])
		@included_planets = Simulation.included_planets(@simulation.id)
		@system = System.find_by_id(@simulation.system_id)
	end

	def save_planets_to_simulation
		body_type_id = BodyType.find(:first, :conditions => { :name => "planet" }).id
		params[:included_planets].each_pair do |key,value|
			if value.to_i == 1
				planet = Planet.find_by_id(key)
				sim_planet = SimulationBody.new
				sim_planet.simulation_id = 3
				sim_planet.body_type_id = body_type_id
				sim_planet.name = planet.name
				sim_planet.mass = planet.mass
				sim_planet.eccentricity = planet.eccentricity
				sim_planet.semi_major_axis = planet.semi_major_axis
				sim_planet.save
			end
		end
		redirect_to :controller => 'systems', :action => 'show', :id => 139
		#else
		#	redirect_to :controller => 'systems', :action => 'index'
		#end
	end

end
